define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    add_url: 'user/user/add',
                    edit_url: 'user/user/edit',
                    del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'users',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'user_id',
                sortName: 'user_id',
                columns: [
                    [
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user_name', title: __('User_name')},
                        {field: 'full_name', title: __('Full_name'),operate:false},
                        {field: 'nickname', title: __('Nickname')},
                        {field: 'head_img', title: __('Head_img'), formatter: Table.api.formatter.image,operate:false},
                        {field: 'sex', title: __('Sex'),operate:false},
                        {field: 'birthday', title: __('Birthday'),operate:false},
                        {field: 'id_number', title: __('Id_number'),operate:false},
                        {field: 'recent_photo', title: __('Recent_photo'), formatter: Table.api.formatter.image,operate:false},
                        {field: 'address', title: __('Address'),operate:false},
                        {field: 'spare_mobile_number', title: __('Spare_mobile_number'),operate:false},
                        {field: 'user_money', title: __('User_money'),operate:false},
                        {field: 'frozen_money', title: __('Frozen_money'),operate:false},
                        {field: 'pay_points', title: __('Pay_points'),operate:false},
                        {field: 'rank_points', title: __('Rank_points'),operate:false},
                        {field: 'credit_line', title: __('Credit_line'),operate:false},
                        {field: 'reg_times', title: __('Last_time'),operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},
                        {field: 'reg_step', title: __('Reg_step'), formatter: Table.api.formatter.status, searchList: __('Reg_steps')},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'detail',
                                text: __('Detail'),
                                icon: 'fa fa-th-large',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'user/user/detail'
                            }],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
                showToggle: false,
                showColumns: false,
                search:false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});